﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.CompilerServices;


namespace DAL.Configuration
{
    [assembly:InternalsVisibleTo("BE")]
    internal class ModulosDAL<T>:IDisposable
    {
        internal List<T> GetList()
        {
            List<T> result = new List<T>();
            string GUID = "51F8ACFD-BDE3-4510-B74A-50864F85D1A1";
            try
            {
                result = new GenericList<T>().GetAGenelicListOf(DAL.Gateway.DataAccessGateway.TraerDataTable(GUID));
            }
            catch (Exception ex)
            {
                throw new Exception("DAL.Configuration - ModulosDA - GetList - ", ex);
            }
            return result;
        }
        internal T Create(string sModuleName, string sDescription)
        {
            T result = Activator.CreateInstance<T>();
            string GUID = "A64F7ED4-CC13-456D-815F-AE9D734BB9B4";
            try
            {
                result = new GenericList<T>().GetAGenelicListOf(DAL.Gateway.DataAccessGateway.TraerDataTable(GUID)).Single();
            }
            catch (Exception ex)
            {
                throw new Exception("DAL.Configuration - ModulosDA - Create - ", ex);
            }
            return result;
        }
        internal T Update(int iModuleId, string sModuleName, string sDescription)
        {
            T result = Activator.CreateInstance<T>();
            string GUID = "5944A72A-8219-4858-879A-2865BC1DD9BB";
            try
            {
                result = new GenericList<T>().GetAGenelicListOf(DAL.Gateway.DataAccessGateway.TraerDataTable(GUID,iModuleId,sModuleName,sDescription)).Single();
            }
            catch (Exception ex)
            {
                throw new Exception("DAL.Configuration - ModulosDA - Update - ", ex);
            }
            return result;
        }
        internal List<T> GetFunctionsList(int iModuleId)
        {
            string spGUID = "12A86387-1589-43AC-8DF6-397AC44B9F8B";
            List<T> result = new List<T>();
            try
            {
                result = new DAL.GenericList<T>().GetAGenelicListOf(DAL.Gateway.DataAccessGateway.TraerDataTable(spGUID, iModuleId));
            }
            catch (Exception ex)
            {
                throw new Exception("DAL.Configuration - ModulosDAL - GetFunctionsList - ", ex);
            }
            return result;
        }
        #region IDisposable Members

        public void Dispose()
        {
        }

        #endregion
    }
}
